<%@page import="by.epam.communalservices.entity.JkhWorker"%>
<%@page import="by.epam.communalservices.dao.jdbc.JdbcDaoJkhWorker"%>

<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib tagdir="/WEB-INF/tags/connect" prefix="connect"%>
<%@ taglib tagdir="/WEB-INF/tags/worker" prefix="worker"%>
<%@ taglib tagdir="/WEB-INF/tags/table" prefix="table"%>
<%@ taglib tagdir="/WEB-INF/tags/team" prefix="team"%>

<connect:isset/>
<connect:denny rules="admin,edit,worker_edit,worker_view,kadrovik,brigadir,tacker,objecter" />

<connect:rule val="editor" rules="admin,edit,worker_edit,kadrovik" />
<connect:rule val="brigadir" rules="admin,edit,worker_edit,kadrovik,brigadir" />


<worker:edit  id="${param.id}" name="${param.name}"
	surname="${param.surname}" patronymic="${param.patronymic}"
	specialty="${param.specialty}" rate="${param.rate}"
	submit="${param.submit}" delete="${param.delete}" />

<c:if test="${form}">
	<worker:append id="${requestScope.worker.id}" remove="${param.remove}"
		add="${param.add}" append="${param.append}" />
</c:if>

<c:if test="${requestScope.message ne ''}">
	<p class='message'>
		<c:out value="${message}" />
	</p>
</c:if>

<c:if test="${param.delete gt 0}">
	<c:import url="/WEB-INF/pages/worker_view.jsp" />
</c:if>
<c:if test="${form}">
	<c:if test="${team}">
		<table:body style="width:300px;float:right;position:relative;" >
			<table:title span="4">
      			Регистрация в бригаде
			</table:title>
			<tr id=c>
				<td colspan=4 id=l>
				<worker:team id="${requestScope.worker.id}" edit="${editor}" link="${true}" />
				</td>
			</tr>
			<table:title span="4" down="yes">
				<c:if test="${editor}">
					<form method='POST' action='worker_edit'>
						<input name='id' value="${requestScope.worker.id}" type="hidden">
						<team:select name="add" selected="0" none="yes"/>
						<input name='append' value='save' type='submit'>
					</form>
				</c:if>
				<connect:display rules="brigadir">
				<worker:contained id="${requestScope.worker.id}">
					<form method='POST' action='worker_edit'>
						<input name='id' value="${requestScope.worker.id}" type="hidden">
						<team:select name="add" selected="0" none="yes" owner="${sessionScope.currentUser.id}"/>
						<input name='append' value='save' type='submit'>
					</form>
				</worker:contained>
				</connect:display>
			</table:title>
		</table:body>
	</c:if>
	<form method='POST' action='worker_edit'  style="clear:left;position:relative;">
		<table:body style='width:50%;'>
			<table:title span="4">
				<c:choose>
				<c:when test="${param.id gt 0}">
      				Редактирование рабочего
  				</c:when>
				<c:otherwise>
      				Добавление рабочего
  				</c:otherwise>
				</c:choose>
			</table:title>

			<input name='id' value="${requestScope.worker.id}" type="hidden">

			<tr id=c>
				<td colspan=2 class=t>Фамилия</td>
				<td colspan=2 class=t id=l>
					<c:choose>
					<c:when test="${editor}">
						<input name='surname' value="${requestScope.worker.surname}" />
  					</c:when>
					<c:otherwise>
						<c:out value="${requestScope.worker.surname}" />
					</c:otherwise>
					</c:choose>
				</td>
			</tr>

			<tr id=c>
				<td colspan=2 class=t>Имя</td>
				<td colspan=2 class=t id=l>
					<c:choose>
					<c:when test="${editor}">
						<input name='name' value="${requestScope.worker.name}" />
  					</c:when>
					<c:otherwise>
						<c:out value="${requestScope.worker.name}" />
					</c:otherwise>
					</c:choose>
				</td>
			</tr>

			<tr id=c>
				<td colspan=2 class=t>Отчество</td>
				<td colspan=2 class=t id=l>
					<c:choose>
					<c:when test="${editor}">
						<input name='patronymic' value="${requestScope.worker.patronymic}" />
  					</c:when>
					<c:otherwise>
						<c:out value="${requestScope.worker.patronymic}" />
					</c:otherwise>
					</c:choose>
				</td>
			</tr>

			<tr id=c>
				<td colspan=2 class=t>Специальность</td>
				<td colspan=2 class=t id=l>
					<c:choose>
					<c:when test="${editor}">
						<input name='specialty' value="${requestScope.worker.specialty}" />
  					</c:when>
					<c:otherwise>
						<c:out value="${requestScope.worker.specialty}" />
					</c:otherwise>
					</c:choose>
				</td>
			</tr>

			<tr id=c>
				<td colspan=2 class=t>Разряд</td>
				<td colspan=2 class=t id=l>
					<c:choose>
					<c:when test="${editor}">
						<table:select items="0,1,2,3,4,5,6,7,8,9" name="rate" attr="style='width:80px;'"
							selected="${requestScope.worker.rate}" />
  					</c:when>
					<c:otherwise>
						<c:out value="${requestScope.worker.rate}" />
					</c:otherwise>
					</c:choose>
				</td>
			</tr>

			<table:title span="4" down="yes">
				<connect:display rules="admin,kadrovik">
					<button type="button" onclick="if (confirm('Уверены?')) document.location.href='worker_edit?delete=${worker.id}'" style="color:red;">delete</button>
				</connect:display>
				<c:if test="${editor}">
					<input name='submit' value='save' type='submit'>
				</c:if>
			</table:title>
		</table:body>
	</form>
</c:if>
